package com.accp.hotevent.util;

import com.accp.hotevent.entity.User;

public abstract class LoggedUserContext {

    private static ThreadLocal<User> currentLoggedUser = new ThreadLocal<>();

    public static void setCurrentLoggedUser(User loggedUser) {
        if (currentLoggedUser == null) {
            currentLoggedUser = new ThreadLocal<>();
        }
        currentLoggedUser.set(loggedUser);
    }

    public static User getCurrentLoggedUser() {
        return currentLoggedUser != null ? currentLoggedUser.get() : null;
    }

    public static void clear() {
        if (currentLoggedUser != null) {
            currentLoggedUser.remove();
        }
    }
}